package com.hhkj.admin.invoice.service.base.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hhkj.admin.invoice.common.cont.InvoiceConst;
import com.hhkj.admin.invoice.domain.Invoice;
import com.hhkj.admin.invoice.mapper.InvoiceMapper;
import com.hhkj.admin.invoice.model.dopo.InvoiceDo;
import com.hhkj.admin.invoice.model.dopo.InvoicePo;
import com.hhkj.admin.invoice.service.base.InvoiceService;
import com.ruoyi.common.base.biz.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

/**
* @author admin
* @description 针对表【s_invoice(记录订单每次开票信息)】的数据库操作Service实现
* @createDate 2023-10-27 11:33:29
*/
@Service
public class InvoiceServiceImpl extends BaseServiceImpl<Invoice, InvoiceDo, InvoicePo, InvoiceMapper>
    implements InvoiceService{

    @Override
    public boolean hasApplied(Long orderId) {
        if (ObjectUtil.isEmpty(orderId)) {
            return false;
        }
        LambdaQueryWrapper<Invoice> queryWrapper = new LambdaQueryWrapper<Invoice>()
                .eq(Invoice::getOrderId, orderId)
                .and(lambdaQueryWrapper -> lambdaQueryWrapper.
                        eq(Invoice::getStatusCode, InvoiceConst.Status.NON.getCode())
                        .or()
                        .eq(Invoice::getStatusCode, InvoiceConst.Status.EFFECTIVE.getCode())
                );
        return count(queryWrapper) > 0;
    }
}




